import pandas as pd
import sys, os

url = '../data/output_csv/sh600000.day_out.csv'

if len(sys.argv) > 1:
    url = sys.argv[1]
df = pd.read_csv(url)
df = df.set_index('date')
df_index = df.index.tolist()
# 选出金叉和27日线比前一天大
df = df[(df['5-13_X'] == 1)]
df_10 = pd.DataFrame()
rootdir = '../data/output_csv'
save_url = '../data/buy_csv/'
if not os.path.exists(save_url):
    os.makedirs(save_url)
list = os.listdir(rootdir)  # 列出文件夹下所有的目录与文件

for i in range(0, len(list)):
    path = os.path.join(rootdir, list[i])
    if os.path.isfile(path):
        if '600000' not in path and '_out' in path:
            df_buy = pd.read_csv(path)
            df_buy = df_buy.set_index('date')
            df_buy = df_buy[df_buy['27diff'] == 1]
            df_buy = df_buy.loc[df_buy.index.intersection(df_index)]
            print(df_buy.head(2))
            file_name = path.split('/')[-1]
            df_buy.to_csv(save_url + file_name.replace('_out', '_buy'))
